<template>
  <section class="view">
    <div class="news_title">
      资讯详情
    </div>
    <div class="news_content flex">
       <div class="content">
            <div class="title">
              <div class="item1">{{ nowItem.title }}</div>
              <div class="item2">{{ nowItem.createTime }}</div>

            </div>
            <div class="con" style='text-indent: 2em; text-align: left;line-height: 24px;' v-html='nowItem.detail'></div>
       </div>
    </div>
  </section>
</template>

<script>
	import judgeTime from '../../../assets/js/index.js'
  export default {
    data () {
      return {
      	nowId: 0,
      	paramsNews: [],
      	nowItem: {}
      }
    },
    beforeMount () {
    	//获取URL链接中的ID
    	this.nowId = this.$route.params.id
    	//请求新闻资讯列表
    	this.require_newsList()
    },
    methods: {
      require_newsList () {
      	this.$api.newsList().then(res => {
      		this.paramsNews = res.data.list
      		for(let i = 0; i < this.paramsNews.length; i++) {
      			//判断当前的是哪一条新闻资讯
      			if(this.paramsNews[i].id == this.nowId) {
      				this.nowItem = this.paramsNews[i]
      				
      				//把获取到的新闻资讯的内容中的img标签替换为空字符串
      				let str = this.nowItem.detail
      				let reg = /<img(.*?)>/
    					let newStr = str.replace(reg, '').replace(reg, '').replace(reg, '')
    					this.nowItem.detail = newStr
    					
    					//时间戳编码转换
    					let dateTime = judgeTime(this.nowItem.createTime)
    					this.nowItem.createTime = dateTime
    					
      			}
      		}
      	})
      }
    }

  }
</script>

<style lang="less" scoped>
  section{
    margin-top: 20px;
  }
  .news_title{
    height: 48px;
    line-height:48px;
    text-align: left;
    padding-left: 40px;
    font-size: 17px;
    font-weight: bold;
    letter-spacing: 5px;
    color: red;
    background: url("../../../../static/img/news_bg.gif") 0 0 no-repeat;
  }
  .content{
    width: 700px;
    border: 2px solid #f9b555;
    padding:30px;
  }
  .title{
    border-bottom: 1px solid #ccc;
    padding-bottom: 25px;
    margin-bottom: 25px;
  }
  .title .item1{
    padding: 15px;
    font-size: 22px;
    font-weight: bold;
    color: #333;
  }
</style>
